plugin('objhelper', function () {
    var ObjHelper = function () {
        this.version = 'v1.0';
    };

    ObjHelper.prototype = {
        constructor: ObjHelper,
        copy: function (target, filter) {
            if (!(target instanceof Object))
                throw new Error('copy object error!');
            var res = {}, self = this;
            Object.keys(target).forEach(function (name) {
                if (filter instanceof Array && filter.indexOf(name) > -1) return;
                // 如果是对象，进行深层次拷贝
                var node = target[name];
                if (typeof node === 'object') {
                    res[name] = self.copy(node);
                    return;
                }
                res[name] = node;
            });
            return res;
        },
        /**
         * function 深层次赋值
         */
        set: function (target, current, cb) {
            if (!(target instanceof Object) || !(current instanceof Object)) return;
            var self = this;
            Object.keys(target).forEach(function (name) {
                var value = current[name];
                if (typeof value !== 'undefined' && target.hasOwnProperty(name)) {

                    // 如果有callback，先执行callback
                    if (typeof cb === 'function') {
                        target[name] = cb(name, value);
                        return;
                    }

                    // 如果是对象，进行深层次拷贝
                    if (typeof target[name] === 'object') {
                        self.set(target[name], current[name], cb);
                        return;
                    }


                    target[name] = target[name].constructor.call(null, value);
                }
            });
        },
        toJson: function (val) {
            if (typeof val === 'string') {
                try { return JSON.parse(val) }
                catch (e) {
                    return false;
                }
            }
            return val;
        }

    };
    return ObjHelper;
});